# StorageWrapper.py
#
# Copyright (c) 2006 Michael Hobbs
#
# This file is part of iTorrent.
#
# iTorrent is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# iTorrent is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iTorrent; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


from BitTorrent.StorageWrapper import StorageWrapper


class patched_StorageWrapper(StorageWrapper):
	def __init__(self, *args, **kwargs):
		super(patched_StorageWrapper, self).__init__(*args, **kwargs)
		self.amountActive = self.total_length - self.amount_inactive
		self.amountHave = self.total_length - self.amount_left
		self.realTotalLength = self.total_length
		if '#only-pieces' not in self.config:
			return
		pieces = self.config['#only-pieces']
		self.realTotalLength = 0
		for piece in pieces:
			self.realTotalLength += self._piecelen(piece)
		self.amount_inactive = self.realTotalLength - self.amountActive
		self.amount_left = self.realTotalLength - self.amountHave

